#ifndef _PIKA_HAL_DEQUE_H_
#define _PIKA_HAL_DEQUE_H_

#include "pika_platform_thread.h"
#include "PikaObj.h"

// #define PIKA_HAL_SIMPLE_DEQUE 
// 定义双向链表节点
typedef struct _Node {
    void* data;
    struct _Node* prev;
    struct _Node* next;
} Node;

// 定义双端队列结构
typedef struct _Deque {
    Node* head;  // 指向队首
    Node* tail;  // 指向队尾
    size_t count;  // 队列中的元素数量
    int maxlen;  // 队列的最大容量
#if PIKA_HAL_DQUEUE_MUTEX_ENABLE
    pika_platform_thread_lock_t lock;  // 互斥锁
#endif
} pika_hal_deque_t;

// 创建一个新的双端队列
pika_hal_deque_t* pika_hal_deque_create(int maxlen);
// 初始化一个新的双端队列
int pika_hal_deque_init(pika_hal_deque_t* deque, int maxlen);



// 在队尾添加元素
int pika_hal_deque_appendTail(pika_hal_deque_t* deque, void* value);

// 在队首添加元素
int pika_hal_deque_appendHead(pika_hal_deque_t* deque, void* value);

// 从队首移除元素
int pika_hal_deque_popHead(pika_hal_deque_t* deque, void** value);

// 从队尾移除元素
int pika_hal_deque_popTail(pika_hal_deque_t* deque, void** value);

// 查看队首元素
int pika_hal_deque_peekHead(pika_hal_deque_t* deque, void** value);

// 查看队尾元素
int pika_hal_deque_peekTail(pika_hal_deque_t* deque, void** value);

// 获取队列中的元素数量
size_t pika_hal_deque_getCount(pika_hal_deque_t* deque);

// 检查队列是否为空
pika_bool pika_hal_deque_isEmpty(pika_hal_deque_t* deque);

// 检查队列是否已满
pika_bool pika_hal_deque_isFull(pika_hal_deque_t* deque);

// 清理内部状态
void pika_hal_deque_deinit(pika_hal_deque_t* deque);
// 销毁对象，释放资源
void pika_hal_deque_delete(pika_hal_deque_t* deque);
#endif  // end of file